let data = [
  {
    workOrderNo: 'WO202406061805525339',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 3000,
    planHour: 3
  },
  {
    workOrderNo: 'WO202406061805520031',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 4000,
    planHour: 13
  },
  {
    workOrderNo: 'WO202406061805525953',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 5000,
    planHour: 1
  },
  {
    workOrderNo: 'WO202406061805525339',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 3000,
    planHour: 3
  },
  {
    workOrderNo: 'WO202406061805520031',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 4000,
    planHour: 13
  },
  {
    workOrderNo: 'WO202406061805525953',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 5000,
    planHour: 1
  },
  {
    workOrderNo: 'WO202406061805525339',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 3000,
    planHour: 3
  },
  {
    workOrderNo: 'WO202406061805520031',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 4000,
    planHour: 13
  },
  {
    workOrderNo: 'WO202406061805525953',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 5000,
    planHour: 1
  },
  {
    workOrderNo: 'WO202406061805525339',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 3000,
    planHour: 3
  },
  {
    workOrderNo: 'WO202406061805520031',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 4000,
    planHour: 13
  },
  {
    workOrderNo: 'WO202406061805525953',
    partNo: 'LB-CP-0020-001',
    partName: '锂电池包',
    planQuantity: 5000,
    planHour: 1
  }
];
function generateRandomTwoDecimalPlaces() {
  let num = (Math.random() * 10).toFixed(2);
  return Number(num);
}

function generateRandomNegativeNumber() {
  let num = (Math.random() - 0.5).toFixed(2);
  return Number(num);
}

// duration最小值为0.5，最大值为0.95
let mockTasksData = [
  { id: 1, type: 'project', render: 'split', text: 'SMT工段:S11产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 10, text: '', parent: 1, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 11, text: '', parent: 1, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 12, text: '', parent: 1, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 13, text: '', parent: 1, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 14, text: '', parent: 1, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 15, text: '', parent: 1, start_date: '2024-09-02', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 16, text: '', parent: 1, start_date: '2024-09-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 2, type: 'project', render: 'split', text: 'DIP工段:S21产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 210, text: '', parent: 2, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 211, text: '', parent: 2, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 212, text: '', parent: 2, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 213, text: '', parent: 2, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 214, text: '', parent: 2, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 3, type: 'project', render: 'split', text: 'DIP工段:S22产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 310, text: '', parent: 3, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 311, text: '', parent: 3, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 312, text: '', parent: 3, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 313, text: '', parent: 3, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 314, text: '', parent: 3, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 4, type: 'project', render: 'split', text: 'DIP工段:S23产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 40, text: '', parent: 4, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 41, text: '', parent: 4, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 42, text: '', parent: 4, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 43, text: '', parent: 4, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 44, text: '', parent: 4, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 5, type: 'project', render: 'split', text: 'DIP工段:S24产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 50, text: '', parent: 5, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 51, text: '', parent: 5, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 52, text: '', parent: 5, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 53, text: '', parent: 5, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 54, text: '', parent: 5, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 6, type: 'project', render: 'split', text: 'DIP工段:S25产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 60, text: '', parent: 6, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 61, text: '', parent: 6, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 62, text: '', parent: 6, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 63, text: '', parent: 6, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 64, text: '', parent: 6, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 7, type: 'project', render: 'split', text: 'DIP工段:S26产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 70, text: '', parent: 7, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 71, text: '', parent: 7, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 72, text: '', parent: 7, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 73, text: '', parent: 7, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 74, text: '', parent: 7, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 8, type: 'project', render: 'split', text: 'DIP工段:S27产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 80, text: '', parent: 8, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 81, text: '', parent: 8, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 82, text: '', parent: 8, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 83, text: '', parent: 8, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 84, text: '', parent: 8, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 9, type: 'project', render: 'split', text: 'DIP工段:S28产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 90, text: '', parent: 9, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 91, text: '', parent: 9, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 92, text: '', parent: 9, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 93, text: '', parent: 9, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 94, text: '', parent: 9, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 100, type: 'project', render: 'split', text: 'DIP工段:S28产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 1001, text: '', parent: 100, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1002, text: '', parent: 100, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1003, text: '', parent: 100, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1004, text: '', parent: 100, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1005, text: '', parent: 100, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 101, type: 'project', render: 'split', text: 'DIP工段:S29产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 1011, text: '', parent: 101, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1012, text: '', parent: 101, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1013, text: '', parent: 101, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1014, text: '', parent: 101, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1015, text: '', parent: 101, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 102, type: 'project', render: 'split', text: 'DIP工段:S30产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 1021, text: '', parent: 102, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1022, text: '', parent: 102, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1023, text: '', parent: 102, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1024, text: '', parent: 102, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1025, text: '', parent: 102, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 103, type: 'project', render: 'split', text: 'DIP工段:S31产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 1031, text: '', parent: 103, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1032, text: '', parent: 103, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1033, text: '', parent: 103, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1034, text: '', parent: 103, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1035, text: '', parent: 103, start_date: '2024-08-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data },
  { id: 104, type: 'project', render: 'split', text: 'DIP工段:S32产线', openLineDuration: 1, clearLineDuration: 1, uph: 100 },
  { id: 1041, text: '', parent: 104, start_date: '2024-08-26', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1042, text: '', parent: 104, start_date: '2024-08-27', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1043, text: '', parent: 104, start_date: '2024-08-28', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1044, text: '', parent: 104, start_date: '2024-08-29', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomTwoDecimalPlaces(), detailData: data },
  { id: 1045, text: '', parent: 104, start_date: '2024-11-30', ljgs: generateRandomTwoDecimalPlaces(), sygs: generateRandomNegativeNumber(), detailData: data }
];
mockTasksData.forEach((item) => {
  if (!item.type) {
    let rate = Number((item.ljgs / (item.sygs + item.ljgs)).toFixed(2));
    if (rate < 0.5) {
      rate = 0.5;
    } else if (rate >= 0.95) {
      rate = 0.95;
    }
    item.duration = rate;
  }
});
export const tasksData = mockTasksData;
export const dateColums = [
  '2024-08-24:周六',
  '2024-08-25:周日',
  '2024-08-26:周一',
  '2024-08-27:周二',
  '2024-08-28:周三',
  '2024-08-29:周四',
  '2024-08-30:周五',
  '2024-08-31:周六',
  '2024-09-01:周日',
  '2024-09-07:周六',
  '2024-09-08:周日',
  '2024-09-14:周六',
  '2024-09-15:周日'
].map((item, index) => {
  let [date, week] = item.split(':');
  return {
    prop: date,
    label: date + '(' + week + ')',
    align: 'center',
    isWorkday: ['周六', '周日'].includes(week) ? 0 : 1,
    children: [
      {
        label: '剩余工时',
        prop: date + ':sygs',
        width: 60,
        align: 'center'
      },
      {
        label: '计划数量',
        prop: date + ':jhsl',
        width: 105,
        align: 'center'
      },
      {
        label: '计划工时',
        prop: date + ':jhgs',
        width: 60,
        align: 'center'
      }
    ]
  };
});

export function getDay(day) {
  const dateArray = [];
  const weekdays = {
    0: '周日',
    1: '周一',
    2: '周二',
    3: '周三',
    4: '周四',
    5: '周五',
    6: '周六'
  };
  if (day == 'sameMonth') {
    let today = new Date();
    let tYear = today.getFullYear();
    let tMonth = today.getMonth();
    tMonth = doHandleMonth(tMonth + 1);
    let times = new Date(tYear, tMonth, 0).getDate();
    for (let i = 1; i <= times; i++) {
      let weekday = new Date(tYear, tMonth - 1, i).getDay();
      dateArray.push(tYear + '-' + tMonth + '-' + (i < 10 ? '0' + i : i) + ':' + weekdays[weekday]);
    }
  } else if (day == 'nextMonth') {
    let today = new Date();
    let tYear = today.getFullYear();
    let tMonth = today.getMonth() + 1;
    tMonth = doHandleMonth(tMonth + 1);
    let times = new Date(tYear, tMonth, 0).getDate();
    for (let i = 1; i <= times; i++) {
      let weekday = new Date(tYear, tMonth - 1, i).getDay();
      dateArray.push(tYear + '-' + tMonth + '-' + (i < 10 ? '0' + i : i) + ':' + weekdays[weekday]);
    }
  } else {
    for (let i = 0; i < day; i++) {
      let today = new Date();
      let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * i;
      today.setTime(targetday_milliseconds);
      let tYear = today.getFullYear();
      let tMonth = today.getMonth();
      let tDate = today.getDate();
      let weekday = today.getDay();
      tMonth = doHandleMonth(tMonth + 1);
      tDate = doHandleMonth(tDate);
      let time = tYear + '-' + tMonth + '-' + tDate + ':' + weekdays[weekday];
      dateArray.push(time);
    }
  }
  console.log(dateArray, 'dateArray');
  return dateArray;
}

export function doHandleMonth(month) {
  var m = month;
  if (month.toString().length == 1) {
    m = '0' + month;
  }
  return m;
}
